package cn.iocoder.yudao.framework.business.basic.pojo.bo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 支持携带额外数据的分页结果
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @see cn.iocoder.yudao.framework.common.pojo.PageResult
 * @author 山野羡民（1032694760@qq.com）
 * @since 2024/12/05
 */
@SuppressWarnings("unused")
@Schema(description = "分页结果")
@Data
public class ExtraPageResult<T> implements Serializable {

    @Schema(description = "数据", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<T> list;

    @Schema(description = "总量", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer total;

    @Schema(description = "额外信息，如累计金额")
    private Map<String, Object> extra;

    public ExtraPageResult() {
        super();
    }

    public ExtraPageResult(List<T> list, Long total) {
        this.list = list;
        this.total = Math.toIntExact(total);
    }

    public ExtraPageResult(List<T> list, Integer total) {
        this.list = list;
        this.total = total;
    }

    public ExtraPageResult(Long total) {
        this.list = new ArrayList<>();
        this.total = Math.toIntExact(total);
    }

    public ExtraPageResult(Integer total) {
        this.list = new ArrayList<>();
        this.total = total;
    }

    public static <T> ExtraPageResult<T> empty() {
        return new ExtraPageResult<>(0);
    }

    public static <T> ExtraPageResult<T> empty(Long total) {
        return new ExtraPageResult<>(total);
    }

    public ExtraPageResult<T> put(String key, Object value) {
        if (extra == null) {
            extra = new Hashtable<>();
        }
        extra.put(key, value);
        return this;
    }

}
